﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using System.ComponentModel.Composition;

using SimpleForum.Contracts;

namespace SimpleForum.Classes.Web
{
    [Export(typeof(IRouteRegistrar)), ExportMetadata("Order", 100)]
    public class DefaultRouteRegistrar : IRouteRegistrar
    {
        public void RegisterIgnoreRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.ico/{*pathInfo}");
        }

        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute(
                "User Login",
                "login",
                new { controller = "User", action = "Login" }
            );

            routes.MapRoute(
                "User Logout",
                "logout",
                new { controller = "User", action = "Logout" }
            );

            routes.MapRoute(
                "Friendly URLs",
                "{controller}/{id}/{name}/{param}",
                new { controller = "Category", action = "View", id = "", name = "", param = UrlParameter.Optional },
                new { id = @"\d+" }
            );

            routes.MapRoute(
                "Default", 
                "{controller}/{action}/{id}",
                new { controller = "Category", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}